import { toSuccess, useEntityManager } from "@sker/core"
import { AutoUser, KsDevice } from "@sker/entities"
import { useData } from "@sker/runtime"
import { z } from "zod"

export default async () => {
    const input = z.object({
        uuid: z.string()
    })
    const body = input.parse(useData())
    const data = await useEntityManager(async m => {
        const device = await m.findOne(KsDevice, { where: { uuid: body.uuid } })
        if (device.owner) {
            const owner = await m.findOne(AutoUser, { where: { mobile: device.owner } })
            if (owner) {
                if (owner.mobile === '18639118753') {
                    return ['zhuabao', 'qiangbao', 'open']
                } else {
                    return ['zhuabao']
                }
            }
        }
        return []
    })
    return toSuccess(data)
}